package org.vectrics.skill.struts;

import org.apache.log4j.Logger;
import org.vectrics.SystemException;
import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.skill.SkillException;
import org.vectrics.skill.SkillRatingSet;
import org.vectrics.skill.UserEvaluation;
import org.vectrics.struts.Request;
import org.vectrics.user.UserSkillRatingSet;



public class UserSaveSkillsAction extends SaveSkillsActionAbstract {
	private transient static Logger log = Logger.getLogger(UserSaveSkillsAction.class);
	
	protected boolean getKeepAllRatings() {
		return(false);
	}
	
	protected void saveSkillRatingSet(Request request, SkillRatingSet ratingSet) throws SkillException {
		log.debug("saveSkillRatingSet() - method to save user ratings");
		String evalId = request.getParameter("ownerId");
		if (evalId == null) {
			log.error("saveSkillRatingSet() - ownerId param not set to evaluationId (is null)");
			throw new SkillException("saveSkillRatingSet() - evalId param not set");
		}
		else {
			log.debug("saveSkillRatingSet() - saving skills for evaluation: " + evalId);
		}

		UserEvaluation evaluation = RecruitServiceLocator.getSkillProvider().findEvaluationById(new Long(evalId)); 
		if (evaluation == null) {
			throw new SystemException("Could not find evaluation for id: " + evalId);
		}
		
		ratingSet.setEvaluation(evaluation);
		RecruitServiceLocator.getSkillProvider().saveUserSkillRatingSet(evaluation, (UserSkillRatingSet)ratingSet);
	}
	
	
	
}
